package com.controller;
import java.io.IOException;
import java.io.PrintWriter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.entity.User;
import com.service.UserManager;

@Controller   //类似Struts的Action
@RequestMapping("/user")
public class UserController {

	@Resource(name = "userManager")
	private UserManager userManager;

    @RequestMapping("/addUser")   // 请求url地址映射，类似Struts的action-mapping
    public String addUser(User user){
    	userManager.save();
		return "/success";

    }

    @RequestMapping("/updateUser")
    public String updateUser(User user,HttpServletRequest request){
            return "/fail";
    }

    @RequestMapping("/delUser")
    public void delUser(User user,HttpServletResponse response){
        String result = "{\"result\":\"error\"}";

        PrintWriter out = null;
        response.setContentType("application/json");

        try {
            out = response.getWriter();
            out.write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    @RequestMapping("/toAddUser")
    public String toAddUser(){
        return "/UserAdd";
    }

    @RequestMapping("/toUpdateUser")
    public String toUpdateUser(User user,HttpServletRequest request){


        return "/UserEdit";
    }

    @RequestMapping("/getAllUser")
    public String getAllUser(HttpServletRequest request){


        return "/UserMain";
    }
}